package org.example.day;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/09/03 9:05
 */
public class Solution2708 {

    public long maxStrength(int[] nums) {
        if(nums.length == 1){
            return nums[0];
        }
        Arrays.sort(nums);
        //先选数字， 再相成
        int sum = 0;
        long res = 0;
        int lastNum = 0;
        List<Integer> numList = new ArrayList<>();

        for (int i = 0; i < nums.length; i++) {
            if(nums[i] < 0){
                sum++;
                numList.add(nums[i]);
                lastNum = nums[i];
            } else if (nums[i] > 0) {
                if(sum % 2 == 1){
                    numList.remove(Integer.valueOf(lastNum));
                    sum = 0;
                }
                numList.add(nums[i]);
            }
        }
        if(sum % 2 == 1){
            numList.remove(Integer.valueOf(lastNum));
        }

        if(!numList.isEmpty()){
            res = 1;
            for (Integer value : numList) {
                res*=value;
            }
        }

        return res;
    }
}
